package com.yu.crm.utils;


import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;


public class TicketUtil {

    /**
     * 推送票务信息
     * @param
     * @return
     */
    public static void push(String urlPath, String param) {
        try {
            // 服务地址
            URL url = new URL(urlPath);
            // 设定连接的相关参数
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoOutput(true);
            connection.setRequestMethod("POST");
            OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
            // 向服务端发送 key = value对
            out.write(param);
            out.flush();
            out.close();
            // 获取服务端的反馈
            String strLine = "";
            String strResponse = "";
            InputStream in = connection.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            while((strLine = reader.readLine()) != null) {
                strResponse += strLine + "\n";
            }
            System.out.println(strResponse);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

